<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cap.bean.Article" %>
<%@ page import="cap.bean.User" %>
<%@ page import="cap.dao.impl.CategoryDaoImpl" %>
<%@ page import="cap.dao.CategoryDao" %>
<%@ page import="cap.bean.Category" %>
<%@ page import="cap.bean.SysCategory" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
    User user= (User)request.getSession().getAttribute("user");//用户信息
    Article art = (Article)request.getAttribute("art");//文章信息
    List<SysCategory> scgList = (List<SysCategory>)request.getAttribute("scgList");//系统分类信息
    String succMsg = (String)request.getSession().getAttribute("succMsg");//更新文章成功
    String errorMsg = (String)request.getSession().getAttribute("errorMsg");//更新文章失败
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>博客</title>
    <link href="<%=basePath%>bootstrap/css/blog-home.css"/>
    <link href="<%=basePath%>bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="<%=basePath%>bootstrap/js/jquery-2.1.1.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"><!--导航条、反色、固定在顶部 -->
    <div class="container"><!--将导航条居中对齐并在两侧添加内补 -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">博客</a><!--设置了内补（padding）和高度（height） -->
        </div>
        <!--导航链接，表格，和切换其他内容-->
        <div class="collapse navbar-collapse"><!--依赖collapse插件、视口足够窄.navbar-collapse内所包含的内容也将不可见-->
            <ul class="nav navbar-nav"><!--导航、导航项-->
                <li><a href="<%=path%>/user?method=index">网站首页</a></li>
            </ul>
            <c:if test="${null!=user&&user.getIsApplied() == 1}">
                <ul class="nav navbar-nav">
                    <li><a href="<%=basePath%>user?method=myblog&userId=${user.id}">我的博客</a></li>
                    <li><a href="<%=basePath%>article?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 博文管理</a></li><!--Glyphicons字体图标-->
                    <li class="divider"></li><!--分割线-->
                    <li><a href="<%=basePath%>category?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 分类管理</a></li><!--Glyphicons字体图标-->
                    <li class="divider"></li>
                    <li><a href="<%=basePath%>comment?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 评论管理</a></li>
                </ul>
            </c:if>
            <c:if test="${user==null}">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="<%=path%>/login.jsp" target="_self">登录</a></li>
                    <li><a href="<%=path%>/register.jsp" target="_self">注册</a></li>
                </ul>
            </c:if>
            <c:if test="${user!=null}">
                <div class="pull-right">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#">欢迎，${user.userName}</a></li>
                        <li><a href="<%=basePath%>user?method=profile&id=${user.id}"><i class="glyphicon glyphicon-cog"></i> 编辑个人信息</a></li>
                        <c:if test="${user.isApplied==1}">
                            <li><a href="<%=basePath%>user?method=bloginfo&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 编辑博客信息</a></li>
                        </c:if>
                        <li><a href="<%=path%>/user?method=logout"><i class="glyphicon glyphicon-off"></i> 登出</a></li>
                    </ul>
                    </li>
                    </ul>
                </div>
            </c:if>
        </div>
    </div>
</nav>
<c:if test="${null != succMsg}">
    <div class="container">
        <div class="alert alert-success">${succMsg}</div>
    </div>
    <%
        request.getSession().removeAttribute("succMsg");
    %>
</c:if>
<c:if test="${null != errorMsg}">
    <div class="container">
        <div class="alert alert-error">${errorMsg}</div>
    </div>
    <%
        request.getSession().removeAttribute("errorMsg");
    %>
</c:if>
<c:if test="${null!=user&&null!=art}">
    <div class="container" style="position: absolute;top: 60px;left: 340px">
        <div class="row col-md-12">
            <div class="col-md-12">
                <div class="col-md-12">
                    <ol class="breadcrumb">
                        <li><a href="<%=basePath%>article?method=manage&userId=${user.id}">博文管理</a></li>
                        <li class="active">编辑文章</li>
                    </ol>
                </div>
                <form class="form-horizontal" style="position: relative;left: 50px" action="<%=path %>/article?method=saveupdate&userId=${user.id}&artId=${art.id}" method="post">
                    <div class="col-md-6">
                        <div class="form-group">
                            <label for="title">标题</label>
                            <input class="form-control" id="title" name="title" type="text" value="${art.title}">
                        </div>
                        <div class="form-group">
                            <label for="sys_category">系统分类</label>
                            <select class="form-control" id="sys_category" name="sys_category" class="span3">
                                <%
                                    if ((null != scgList) && (scgList.size() > 0)) {
                                        int scgId = art.getSysCategoryId();	//当前文章所属系统分类的id

                                        for (SysCategory scg : scgList) {
                                            if (scgId == scg.getId()) {
                                %>
                                <option value="<%=scgId %>" selected><%=scg.getCategoryName() %></option>
                                <%
                                } else {
                                %>
                                <option value="<%=scg.getId() %>"><%=scg.getCategoryName() %></option>
                                <%
                                        }
                                    }
                                } else { %>
                                <%="获取系统分类失败" %>
                                <% } %>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="category">个人分类</label>
                            <select class="form-control"  id="category" name="category">
                                <%
                                    int userId = user.getId();
                                    CategoryDao cgDao = new CategoryDaoImpl();
                                    List<Category> cgList = cgDao.getByUserId(userId);
                                    int cgId = art.getCategoryId();
                                    if ((null != cgList) && (cgList.size() > 0)) {
                                        for (Category cg : cgList) {
                                            if (cg.getIsDelete() == 0) {
                                                if (cgId == cg.getId()) {
                                %>
                                <option value="<%=cgId %>" selected><%=cg.getCategoryName() %></option>

                                <% 		} else {	%>
                                <option value="<%=cg.getId() %>"><%=cg.getCategoryName() %></option>

                                <%			}
                                }
                                }
                                } else { %>
                                <%="获取个人分类失败" %>
                                <% } %>
                            </select>
                        </div>
                        <div class="form-group">
                            <textarea class="form-control" id="message1" name="summary" class="span6" placeholder="摘要" rows="5">${art.summary}</textarea>
                        </div>

                        <div class="form-group">
                            <textarea class="form-control" id="message2" name="content" class="span6" placeholder="文章内容" rows="5">${art.content}</textarea>
                        </div>

                        <div class="form-group">
                            <button id="contact-submit" type="submit" class="btn btn-primary input-medium pull-right">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</c:if>
<div class="container" style="position: absolute;bottom: 10px;left: 360px">
    <hr>
    <footer style="text-align: center">
        <div class="row">
            <div class="col-lg-12">
                <p>
                    &middot;网站创建到目前访问人数：<%=(Integer)session.getAttribute("num") %>
                </p>
            </div>
        </div>
    </footer>
</div>
</div>
<div><audio autoplay="autoplay" loop="true"><source src="music/1.mp3"></audio></div>
</body>
</html>